package com.freewater.cargotracker.domain.model.handlingevent;

import org.apache.commons.lang3.Validate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class HandlingHistory {

    private List<HandlingEvent> events;

    // Null object pattern.
    public static final HandlingHistory EMPTY = new HandlingHistory(
            Collections.<HandlingEvent>emptyList());

    public HandlingHistory(Collection<HandlingEvent> handlingEvents) {
        Validate.notNull(handlingEvents, "Handling events are required");
        Validate.noNullElements(handlingEvents, "Handling event can't be null");
        this.events = new ArrayList<>(handlingEvents);
    }

    public List<HandlingEvent> getEvents() {
        return Collections.unmodifiableList(events);
    }

    @Override
    public String toString() {
        return "HandlingHistory{" +
                "events=" + events +
                '}';
    }
}
